#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>

#define FOR(i,a,n) for(int i=a;i<n;++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
int dp[100000];
const int V = 77777;
void ZeroOnePack(int c, int w, int dp[]){
    for(int v=V; v>=c; --v)
        if(dp[v-c]+w < dp[v])
            dp[v] = dp[v-c]+w;
    return;
}

void CompletePack(int c, int w, int dp[]){
    for(int v=c; v<=V; ++v)
        if(dp[v-c]+w < dp[v])
            dp[v] = dp[v-c]+w;
    return;
}

void MultiplePack(int c, int w, int m, int dp[]){
    //printf("pack %d,%d\n",c,m);
    if(m*c>=V){
        CompletePack(c, w, dp);
        return;
    }
    int k=1;
    while(k<m){
        ZeroOnePack(k*c, k, dp);
        m-=k;
        k*=2;
    }
    ZeroOnePack(m*c, m, dp);
}
class DSU
{
    int *father;
    public:
    DSU(int n = 0)
    {
        father = new int[n];
        REP(i,n) father[i] = i;
    }
    int getGroup(int x)
    {
        if(father[x]!=x) father[x] = getGroup(father[x]);
        return father[x];
    }
    bool merge(int a,int b)
    {
        int x = getGroup(a);
        int y = getGroup(b);
        if(x==y) return false;
        else
        {
            father[x] = y;
            return true;
        }
    }
};
int ans = 1<<29;
void dfs(int num)
{
    if(num>77777) return ;
    if(dp[num]<ans) ans=dp[num];
    dfs(num*10+4);
    dfs(num*10+7);
}
int main()
{
    int n,m;
    cin>>n>>m;
    DSU dsu(n+1);
    while(m--)
    {
        int u,v;
        cin>>u>>v;
        dsu.merge(u,v);
    }
    vector<int> cnt(n+1,0);
    vector<int> si(n+1,0);
    FOR(i,1,n+1) si[dsu.getGroup(i)]++;
    FOR(i,1,n+1) cnt[si[i]]++;
    fill(dp,dp+100000,1<<29);
    dp[0]=0;
    FOR(i,1,n+1) if(cnt[i])
    {
        MultiplePack(i,1,cnt[i],dp);
    }
    dp[0]=1<<29;
    dfs(0);
    cout<<((ans==1<<29)?-1:ans-1)<<endl;
	return 0;
}
